﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MvcCarConsume.WebUI;
using System.ComponentModel.DataAnnotations;
using MvcCarConsume.App_GlobalResources;
using System.ComponentModel;

namespace MvcCarConsume.UnitTest
{
    [TestClass]
    public class ModelTest
    {
        private class FackModel : VMBase
        {
            private string PrivateProperty { get; set; }
            protected string ProtectedProperty { get; set; }
            public string PublicProperty1 { get; set; }
            [Display(Name="AdminText", ResourceType = typeof(Resources))] //Admin
            public string PublicProperty2 { get; set; }
            [Display(Name = "AdminText", ResourceType = typeof(Resources))]
            [DisplayName("DiplayNameAdmin")]
            public string PublicProperty3 { get; set; }
            [DisplayName("DiplayNameAdmin")]
            public string PublicProperty4 { get; set; }
            [DisplayNameDerived("DiplayNameAdmin")]
            public string PublicProperty5 { get; set; }
            [Display(Name = "AdminText1", ResourceType = typeof(Resources))] //no such key
            public string PublicProperty6 { get; set; }

        }
        public class DisplayNameDerivedAttribute : DisplayNameAttribute
        {
            public DisplayNameDerivedAttribute(string displayName) : base(displayName) { }
        }

        [TestMethod]
        public void VMBase_GetPropertyDisplayName_Test()
        {
            FackModel fm = new FackModel();

            Assert.IsNull(fm.GetPropertyDisplayName("NaN"));
            Assert.IsNull(fm.GetPropertyDisplayName("PrivateProperty"));
            Assert.IsNull(fm.GetPropertyDisplayName("ProtectedProperty"));
            fm.GetPropertyDisplayName("PublicProperty1").ShouldEqual("PublicProperty1");
            fm.GetPropertyDisplayName("PublicProperty2").ShouldEqual("Admin");
            fm.GetPropertyDisplayName("PublicProperty3").ShouldEqual("DiplayNameAdmin");
            fm.GetPropertyDisplayName("PublicProperty4").ShouldEqual("DiplayNameAdmin");
            fm.GetPropertyDisplayName("PublicProperty5").ShouldEqual("DiplayNameAdmin");
            fm.GetPropertyDisplayName("PublicProperty6").ShouldEqual("PublicProperty6");
        }
    }
}
